package ewa

import (
	"net/http"
  "fmt"
	"github.com/labstack/echo"
)

type NonRestrictRouteCb func(echo.Context) error

/* Non-Restrict Route GET, 
   不需要cookies, 
   不需要token验证, 
   直接返回页面或者http response  */
func CbNonCookieTokenGet(c echo.Context) error {
  //fmt.Printf("Path: %s\n", c.Path())	//such like as '/test.html'
  utype, uri := HttpReqPathSuffix(c.Path())

  if utype == URITYPE_RES {
    //指定网页模板名称: uri
    l:=fmt.Sprintf("----Echo/> Response render page[%s]", uri)
    Log(l)
    return c.Render(http.StatusOK, uri, "")
  }else if utype == URITYPE_API {
      // 
      if CfgRoute.MApiAttr[uri].SyncAck == true {
        return SyncApiResponse(uri, c)
      }else{
        return AsyncApiResponse(uri, c)
      }
  }
  return nil
}

func RouteRegistry_NonCookieTokenGet(route string, e *echo.Echo, cb NonRestrictRouteCb) {
  l:=fmt.Sprintf("----Echo/> regist NonCookieTokenGet '%s'", route);Log(l)
	e.GET(route, (echo.HandlerFunc)(cb))
}